Refactor stack traces: named frames, root frame, and builtin collapsing#635
Merged
stephenamar-db merged 2 commits intomasterfrom Mar 5, 2026
Merged
Refactor stack traces: named frames, root frame, and builtin collapsing#635stephenamar-db merged 2 commits intomasterfrom
stephenamar-db merged 2 commits intomasterfrom
Conversation
Rework error stack traces to use descriptive frame names instead of AST node type names. Frames now show function names (e.g. [foo], [std.assertEqual]) and always include a [<root>] outermost frame. Builtin errors are collapsed into the error message prefix when the error originates from Scala code. Key changes: - Add callTargetName to extract function names from Apply AST nodes - Filter frames to only keep Apply/Builtin expression types - Custom formatError with frame collapsing and "Caused by" chain support - Remove functionNamePrefix from Val.Func error messages - Add root frame injection in Interpreter.evaluateImpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rework error stack traces to produce cleaner, more informative output using the existing Java stack trace mechanism (no custom call stack). This is an alternative to #633 that avoids the performance regression by resolving names at parse time and filtering frames during formatting rather than maintaining a separate call stack.
Key changes
Named frames from AST:
callTargetNameextracts function names fromApplyAST nodes at the expression level ([foo],[std.assertEqual],[anonymous]), replacing opaque node type names like[Apply0],[Apply3].Frame filtering: Only
Apply*andApplyBuiltin*expression frames are kept in stack traces, filtering out intermediate AST node types that add noise.Root frame: Every stack trace now includes a
[<root>]outermost frame pointing to the top-level expression, injected byInterpreter.evaluateImpl.Builtin error collapsing: When an error originates from inside a builtin's Scala code (e.g., type checking, missing arguments), the builtin name is collapsed into the error message as a prefix rather than shown as a separate frame:
sjsonnet.Error: [std.manifestTomlEx] Wrong parameter type: expected Object, got arraysjsonnet.Error: [foo] Too many args, has 2 parameter(s)Same-position collapsing: Adjacent frames at the same file position are collapsed to avoid redundant lines.
Caused-by chain:
formatErrornow includesCaused by:output for wrapped exceptions (e.g., native function panics).Removed redundant prefixes:
"Function "prefix removed from error messages since the frame name now provides that context.Example outputs
Builtin error (collapsed into message):
Function parameter error (collapsed):
Error inside function body (full trace):
Native function panic (with caused-by):
Test plan